﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for BalanceDAL
/// </summary>
public class BalanceDAL
{
    DABasic _dabasic;
	public BalanceDAL()
	{
        _dabasic = new DABasic();
	}

    public int naptien(int @userid, string @password, int @sotiennapvao)
    {
        string _query = "balance_naptien";
        SqlParameter[] _para = new SqlParameter[4];
        _para[0] = new SqlParameter("@userid", SqlDbType.Int); 
        _para[0].Value = @userid;
        _para[1] = new SqlParameter("@password", SqlDbType.VarChar,-1);
        _para[1].Value = @password;
        _para[2] = new SqlParameter("@sotiennapvao", SqlDbType.Int);
        _para[2].Value = @sotiennapvao;
        _para[3] = new SqlParameter("@balance", SqlDbType.Int);
        _para[3].Direction = ParameterDirection.Output;

        SqlParameterCollection collect = _dabasic.ExecuteGetOutput(_query, _para, CommandType.StoredProcedure);

        return Convert.ToInt32(collect["@balance"].Value);
    }

    public int ruttien(int @userid, string @password, int @sotienrut)
    {
        string _query = "balance_rutTien";
        SqlParameter[] _para = new SqlParameter[4];
        _para[0] = new SqlParameter("@userid", SqlDbType.Int);
        _para[0].Value = @userid;
        _para[1] = new SqlParameter("@password", SqlDbType.VarChar, -1);
        _para[1].Value = @password;
        _para[2] = new SqlParameter("@sotienrut", SqlDbType.Int);
        _para[2].Value = @sotienrut;
        _para[3] = new SqlParameter("@balance", SqlDbType.Int);
        _para[3].Direction = ParameterDirection.Output;

        SqlParameterCollection collect = _dabasic.ExecuteGetOutput(_query, _para, CommandType.StoredProcedure);

        return Convert.ToInt32(collect["@balance"].Value);
    }

    public int chuyenkhoan(int @senderid, string @password, string @receivername, int @sotien)
    {
        string _query = "balance_chuyenkhoan";
        SqlParameter[] _para = new SqlParameter[5];
        _para[0] = new SqlParameter("@senderid", SqlDbType.Int);
        _para[0].Value = @senderid;
        _para[1] = new SqlParameter("@password", SqlDbType.VarChar, -1);
        _para[1].Value = @password;
        _para[2] = new SqlParameter("@sotien", SqlDbType.Int);
        _para[2].Value = @sotien;
        _para[3] = new SqlParameter("@receivername", SqlDbType.VarChar,-1);
        _para[3].Value = @receivername;
        _para[4] = new SqlParameter("@balance", SqlDbType.Int);
        _para[4].Direction = ParameterDirection.Output;

        SqlParameterCollection collect = _dabasic.ExecuteGetOutput(_query, _para, CommandType.StoredProcedure);

        return Convert.ToInt32(collect["@balance"].Value);
    }

    public DataSet bankList()
    {
        string _query = "SELECT * FROM Banks";
        SqlParameter[] _para = new SqlParameter[0];
        DataSet ds = _dabasic.ExecuteGetDataSet(_query, _para, CommandType.Text);
        return ds;
    }

    public DataSet balanceinfo(int @userid)
    {
        string _query = "balance_getBalanceInfo";
        SqlParameter[] _para = new SqlParameter[1];
        _para[0] = new SqlParameter("@userid", SqlDbType.Int);
        _para[0].Value = @userid;

        DataSet ds = _dabasic.ExecuteGetDataSet(_query, _para, CommandType.StoredProcedure);
        return ds;
    }

    public DataSet transactionlogs(int @userid,object @fromDay,object @toDay,string @type)
    {
        string _query = "balance_transactionlogs";
        SqlParameter[] _para = new SqlParameter[4];
        _para[0] = new SqlParameter("@userid", SqlDbType.Int);
        _para[0].Value = @userid;
        _para[1] = new SqlParameter("@fromDay", SqlDbType.DateTime);
        _para[1].Value = @fromDay;
        _para[2] = new SqlParameter("@toDay", SqlDbType.DateTime);
        _para[2].Value = @toDay;
        _para[3] = new SqlParameter("@type", SqlDbType.NVarChar,-1);
        _para[3].Value = @type;

        DataSet ds = _dabasic.ExecuteGetDataSet(_query, _para, CommandType.StoredProcedure);
        return ds;
    }
}
